import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class Test {

    static public int halveArray(int[] nums) {
        PriorityQueue<Double> priorityQueue = new PriorityQueue<>(new Comparator<Double>() {
            @Override
            public int compare(Double o1, Double o2) {
                if(o2 > o1) return 1;
                else if(o2 == o1) return 0;
                else return -1;
            }
        });

        Double sum = 0.0;
        for(int i = 0; i < nums.length; i++) {
            priorityQueue.offer((double)nums[i]);
            sum += nums[i];
        }

        int count  = 0;
        Double s = 0.0;
        while(s<sum/2) {
            Double t = priorityQueue.poll();
            s += t/2;
            priorityQueue.offer(t/2);
            count++;
        }

        return count;
    }

    public static boolean lemonadeChange(int[] bills) {
        int ten = 0;
        int five = 0;
        for(int i = 0; i < bills.length; i++) {
            if(bills[i] == 5) {
                five++;
            }else if(bills[i] == 10) {
                if(five == 0) {
                    return false;
                }else {
                    five--;
                    ten++;
                }
            }else {
                if(ten > 0) {
                    ten--;
                    bills[i]-=10;
                }
                while(bills[i]>5) {
                    if(five<=0) {
                        return false;
                    }
                    bills[i]-=5;
                    five--;
                }
            }
        }
        return true;
    }
    public static void main(String[] args) {
        int[] arr = {5,19,8,1};
        System.out.println(halveArray(arr));
    }
}
